package com.wqz.controller;

import com.wqz.pojo.Address;
import com.wqz.service.AddressService;
import com.wqz.utils.MessageJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RequestMapping("/address")
@RestController
public class AddressController {

    @Autowired
    private AddressService addressService;

    @RequestMapping("/findAll")
    public MessageJson<List<Address>> findAll() {
        MessageJson<List<Address>> messageJson = null;
        try {
            messageJson = addressService.findAll();
        } catch (Exception e) {
            e.printStackTrace();
            messageJson = new MessageJson<>("500","程序错误。",null);
        }

        return messageJson;
    }
    @RequestMapping("/findAddressDesc")
    public MessageJson<List<Address>> findAddressDesc(@RequestParam("addressDesc") String addressDesc) {
        MessageJson<List<Address>> messageJson = null;
        try {
            messageJson = addressService.findByAddressDesc(addressDesc);
        } catch (Exception e) {
            e.printStackTrace();
            messageJson = new MessageJson<>("500","程序错误。",null);
        }

        return messageJson;
    }

}
